<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${key}">
	<!-- ${ZhKey}resultMap -->
	<resultMap id="${classKey}ResultMap" type="${EntityClass}">
	<#list fieldList as field>
		<result property="${field.name}" column="${field.columnName}"></result>
	</#list> 
	</resultMap>
	<!-- 插入${ZhKey}记录 -->
	<insert id="insert${UpperKey}" parameterType="${EntityClass}" useGeneratedKeys="true" keyProperty="${primaryKey}">
		INSERT INTO ${tableName} 
			( 
			<#list fieldList as field>
			  <#if field.priKey?c ='false'>
			  	${field.columnName}<#if field_has_next>,</#if>
			  </#if>
			</#list>
			)
			VALUES
			(
		<#list fieldList as field>
			 <#if field.priKey?c ='false'>
			  	${propertyPrefix}${field.name}${propertyPostfix}<#if field_has_next>,</#if>
			  </#if>
		</#list>
			) 
	</insert>
	<!-- 更新${ZhKey}记录 -->
	<update id="update${UpperKey}"  parameterType="${EntityClass}">
		update ${tableName} set  
		<#list noCommonFieldList as field>
			<#if field.priKey?c ='false'>
			${field.columnName}=${propertyPrefix}${field.name}${propertyPostfix},
			</#if>
		</#list> 
			updated_by = ${propertyPrefix}updatedBy${propertyPostfix},
			updated_time=now()
		 where ${primaryColumn}=${propertyPrefix}${primaryKey}${propertyPostfix}
	</update>
	<sql id="sql_${classKey}List">
		SELECT 
		<#list fieldList as field>
			${field.columnName}<#if field_has_next>,</#if>
		</#list> 
		 FROM ${tableName} where is_disabled=0
	</sql>

	<select id="query${UpperKey}s" parameterType="java.util.HashMap" resultMap="${classKey}ResultMap">
		<include refid="sql_${classKey}List"/>
		<#list fieldList as field>
		  <#if field.priKey?c ='false'>
		  <if test="${key}.${field.name} != null and ${key}.${field.name} != ''">
		  	and ${field.columnName}=${propertyPrefix}${key}.${field.name}${propertyPostfix}
		  </if>
		  </#if>
		</#list>
		limit ${propertyPrefix}firstRow${propertyPostfix},${propertyPrefix}rowSize${propertyPostfix}
	</select>
	<select id="get${UpperKey}Count" parameterType="${EntityClass}" resultType="java.lang.Long">
		select count(*) from ${tableName} where is_disabled=0
		<#list fieldList as field>
		  <#if field.priKey?c ='false'>
		  <if test="${field.name} != null and ${field.name} != ''">
		  	and ${field.columnName}=${propertyPrefix}${field.name}${propertyPostfix}
		  </if>
		  </#if>
		</#list>
	</select>
	<!-- 根据主键查询${ZhKey}记录 -->
	<select id="get${UpperKey}ByCode" parameterType="${primaryKeyType}" resultMap="${classKey}ResultMap">
		select 
		<#list fieldList as field>
			${field.columnName}<#if field_has_next>,</#if>
		</#list> 
		from ${tableName} where ${primaryColumn}=${propertyPrefix}${primaryKey}${propertyPostfix}
	</select>
	<!-- 删除${ZhKey}记录 -->
	<delete id="delete${UpperKey}"  parameterType="${EntityClass}">
		update ${tableName} set is_disabled=1,
		updated_by=${propertyPrefix}updatedBy${propertyPostfix},
		updated_time=now()
		 where ${primaryColumn}=${propertyPrefix}${primaryKey}${propertyPostfix}
	</delete>
</mapper>